package xyz.yeidi.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @Author JIP
 * @Date 2021-07-29 10:41
 * @Version 1.0
 * @Describe :  中文过滤处理,统一所有的字符集
 */
@WebFilter("/*")
public class CharsetFilter implements Filter {
    public void destroy() {

    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setCharacterEncoding("utf8");
        resp.setContentType("application/json;charset=utf8");
        System.out.println("访问字符集过滤器");
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
